<?php
session_start();
if(isset($_GET['link']))
{
	include_once("../DataProvider.php");
	$link = $_GET['link'];
	$id = substr($link,strpos($link,"id"),11);
	$sql = "SELECT * FROM tbl_games WHERE GameLink like '%$id%'";
	$result = DataProvider::ExecuteQuery($sql);
	if($data1 = mysql_fetch_array($result))
	{
		echo '<script type="text/javascript"> alert("Game đã có trên shop!");</script>';
		
		?>
		<div class="" style="background-color:#162851;
    height: 190px;
    margin-left: 5px;
    margin-top: 5px;
    position: relative;
    text-align: center;
    width: 140px;" >
  
     <div  class="div<?php echo "1_".$data1["GameID"]?>" style="background: url(<?php echo $data1["Artwork"]?>)no-repeat; float:left; margin-left:15px; margin-top:5px; background-size:100px;">
	<img onmouseout="javascript:mouseout(this)" onmouseover="javascript:mouseover(this)" id="img<?php echo "1_".$data1["GameID"] ?>" class="<?php if(isset($_SESSION['listGame']))
	 { 
	 	if(in_array($data1['GameID'],$_SESSION['listGame']))
		{
			echo 'Selected';
			
			}
			else
			{
				echo 'unSelect';
			}
		
		
	 }else echo 'unSelect';
	 ?>" alt="" src="<?php if(isset($_SESSION['listGame']))
	 { 
	 	if(in_array($data1['GameID'],$_SESSION['listGame']))
		{
			echo 'img/mask175_check.png';
			
			}
			else
			{
				echo 'img/mask175_2.png';
			}
		
		
	 }else echo 'img/mask175_2.png';
	 ?>" height="100px" width="100px" style=" cursor: pointer;" onclick="javascript:add(this)" />
    </div>
    

   <div  class="textGame" title="<?php echo $data1['GameName']?>" ><span style="cursor:pointer;" onclick="javascript:loadScreenShoot('<?php echo $data1["GameID"]  ?>')">
    <?php 
   $tengame = "";
    if(strlen($data1["GameName"])>15)
    {
        $tengame = substr($data1["GameName"],0,15)."...";}
    else{ 
    $tengame = $data1["GameName"];} echo $tengame; ?>
    
    <br />  <span style="color:#C33; font-size:12px"><?php echo number_format($data1["Price"], 0, '.', ','); ?> 
    </span>VNĐ&nbsp;&nbsp;<span style="color:#666;"><?php if($data1["Size"]>1000)	
	 		echo number_format($data1["Size"]/1000,2,".",","). " GB"; 
		else
			echo number_format($data1["Size"],2,".",",") . " MB";?>
    </span>
    </div>
    <p>
    <span style="font-size:13px; color:#FFFBF0;" title="<?php echo $data1["Notes"];  ?>"><?php echo substr($data1["Notes"],0,55)."..."; ?></span>
    </p></div>  
</div>

	<?php 
	}
	else
	{
		$sql = "SELECT * FROM tbl_request WHERE linkrequest like '%$id%'";
		$result = DataProvider::ExecuteQuery($sql);
		if($data1 = mysql_fetch_array($result))
		{
		echo '<script type="text/javascript"> alert("Game bạn yêu cầu sẽ được\n cập nhật trong thời gian sớm nhât!");</script>';
			
		}else
		{
			$date = date('Y-m-d');
			$sql1 = "insert into tbl_request(LinkRequest,RequestDate) values ('$link','$date')";
			$result1 = DataProvider::ExecuteQuery($sql1);
			if($result1)
			{
				echo '<script type="text/javascript"> alert("Game bạn yêu cầu sẽ được\n cập nhật trong thời gian sớm nhât!");</script>';
			}
		}
	}
}
?>